package com.thx.appserver.action;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.thx.appserver.model.CappOpinion;
import com.thx.appserver.service.CappOpinionManager;
import com.thx.common.struts2.CurdAction;
import com.thx.common.web.ActionResult;


/**
 * 建立日期 : Jul 31, 2012 4:25:39 PM<br>
 * 作者 : 乔红红<br>
 * 模块 : <br>
 * 描述 : <br>
 * 修改历史: 序号 日期 修改人 修改原因 <br>
 * 1 <br>
 * 2 <br>
 */
@Namespace("/appserver")
@Action(value="opinion", results = {
		@Result(name = "list", location = "/com/thx/appserver/opinion/list.jsp"),
		@Result(name = "view", location = "/com/thx/appserver/opinion/detail.jsp"),
		@Result(name = "json", type = "json", params = { "root", "result" }), })
@Controller
@Scope("prototype")
public class OpinionAction extends CurdAction<CappOpinion> {

	private static final long serialVersionUID = 1L;



	@Autowired
	private CappOpinionManager opinionMgr;

	private List<Object> opinionTypes;

	private String selectOps;

	public OpinionAction() {
	}

	protected void doList() throws Exception {
		entity.setOpinionType(selectOps);
		list =opinionMgr.searchOpinions(entity);
		opinionTypes =opinionMgr.getOpinion();
		System.out.println(opinionTypes.size());
	}



	protected void doView() throws Exception {
		if (StringUtils.isNotBlank(id)) {
			entity = opinionMgr.get(Long.valueOf(id));
			if (entity == null) {
				setResult(ActionResult.FAIL, "要查看的记录不存在！！！");
			}
		} else {
			setResult(ActionResult.FAIL, "服务器异常！");
		}
	}

	protected void doDelete() throws Exception {
		if (StringUtils.isNotBlank(id)) {
			opinionMgr.delete(Long.valueOf(id));
			setResult(ActionResult.SUCCESS, "删除成功！！！");
		} else {
			setResult(ActionResult.FAIL, "服务器异常！");
		}
	}

	protected void doDelMulti() throws Exception {
		if (delId != null && delId.length > 0) {
			Long[] delIds=new Long[delId.length];
			for(int i=0;i<delId.length;i++){
				delIds[i]=Long.valueOf(delId[i]);
			}
			opinionMgr.delMulti(delIds);
			setResult(ActionResult.SUCCESS, "删除成功！！！");
		} else {
			setResult(ActionResult.FAIL, "服务器异常！");
		}
	}


	public CappOpinionManager getOpinionMgr() {
		return opinionMgr;
	}

	public void setOpinionMgr(CappOpinionManager opinionMgr) {
		this.opinionMgr = opinionMgr;
	}


	public List<Object> getOpinionTypes() {
		return opinionTypes;
	}

	public void setOpinionTypes(List<Object> opinionTypes) {
		this.opinionTypes = opinionTypes;
	}

	public String getSelectOps() {
		return selectOps;
	}

	public void setSelectOps(String selectOps) {
		this.selectOps = selectOps;
	}

}
